package com.yy.crypto;

import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.symmetric.AES;

import java.nio.charset.StandardCharsets;

/**
 * 使用 hutool 工具类实现的AES加密
 * @Author: lyy
 * Date: 2021/12/15 17:10
 */
public class AesHutoolUtil {

	private static final String KEY = "1234567812345678";

	public static void main(String[] args) {
		String content = "test中文";
		String encrypt = encrypt(content, KEY);
		System.out.println(encrypt);
		System.out.println(decrypt(encrypt, KEY));
	}

	public static String encrypt(String content, String key){
		AES aes = new AES(Mode.ECB, Padding.PKCS5Padding, key.getBytes());
		return aes.encryptHex(content);
	}

	public static String decrypt(String encryptHex, String key){
		AES aes = new AES(Mode.ECB, Padding.PKCS5Padding, key.getBytes());
		return aes.decryptStr(encryptHex, StandardCharsets.UTF_8);
	}

}
